require(['init'], function () {
    var $pagination = $('#js-pagination')
    var pagination

    var needPw = true;
    //添加学生的dom
    var $Addstudent = $('<div class="paraList" id="J_enroll_wrap">' +
        '<input class="form-control" type="hidden" name="studentuid" >' +
        '<h4 style="margin-left:15px">' + i18next.t('info.classininfo') + '</h4>' +
        '<div class="li line">' +
        '<div class="title required">' +
        '<span><label style="color:red";position: relative;left: -2px;>*</label>' + i18next.t('info.classinaccountnumber') + ':</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control a1" type="text" name="ClassInNo" >' +
        '<div class="inputErrorTips" style="display: none;"></div>' +
        '<input class=""  type="button"  name="" value="检测" id="classIntest" style="margin-left:10px;" style="display:none">' +
        '<input class=""  type="button"  name="" value="重置密码" id="resetpassword" style="margin-left:10px;">' +
        '<div style="margin-top:4px;color:#2ba76c;font-size:12px;display:none" id="prompt">账号已存在，可正常使用</div>' +
        '</div>' +
        '</div>' +
        '<div class="li pw" style="display:none">' +
        '<div class="title">' +
        '<span>初始密码：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control a1" type="text" name="pw" >' +
        '<div style="margin-top:4px;color:red;font-size:12px;display:none" id="noprompt">账号尚未注册，请设置初始密码</div>' +
        '</div>' +
        '</div>' +
        '<h4 style="clear:both;margin-left:15px;padding-top:22px;">' + i18next.t('info.basicinformation') + '</h4>' +
        '<div class="li">' +
        '<div class="title required">' +
        '<span><label style="color:red";position: relative;left: -2px;>*</label>' + i18next.t('info.studentname') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control focus a1" data-formcheck="length" type="text" name="name" >' +
        '<div class="inputErrorTips" style="display: none;"></div>' +
        '</div>' +
        '</div>' +
        '<div class="li">' +
        '<div class="title required">' +
        '<span><label style="color:red";position: relative;left: -2px;>*</label>' + i18next.t('info.loginAccount') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control focus a1"  type="text" name="account" disabled >' +  //-----------------登录账户
        '<div class="inputErrorTips" style="display: none;"></div>' +
        '</div>' +
        '</div>' +
        '<div class="li">' +
        '<div class="title formTitle">' +
        '<span>' + i18next.t('info.sex') + '：</span>' +
        '</div>' +
        '<div class="formContent genderWrap" style="line-height:32px">' +
        ' <span>' +
        ' <span class="icon icon-size-16 icon-radio " data-type="checkbox">' +
        ' <input type="checkbox" name="gender" data-checkedmax="1" value="0">' +
        ' </span><span data-type="label">' + i18next.t('sex.man') + '</span>' +
        '  </span>&nbsp;' +
        ' <span>' +
        ' <span class="icon icon-size-16 icon-radio" data-type="checkbox">' +
        '  <input type="checkbox" name="gender" data-checkedmax="1" value="1">' +
        '  </span><span data-type="label">' + i18next.t('sex.woman') + '</span>' +
        ' </span>' +
        '</div>' +
        '</div>' +
        '<div class="li">' +
        '<div class="title required">' +
        '<span><label style="color:red";position: relative;left: -2px;>*</label>' + i18next.t('info.studentphone') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control focus a1" type="text" data-formcheck="length,justnumber"  name="mobile" >' +
        '<div class="inputErrorTips" style="display: none;"></div>' +
        '</div>' +
        '</div>' +
        '<div class="li">' +
        '<div class="title required">' +
        '<span>' + i18next.t('info.emailaddress') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control a1" type="text" name="email"  >' +
        '</div>' +
        '</div>' +

        '<div class="li">' +
        '<div class="title required">' +
        '<span>' + i18next.t('info.school') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control a1"  type="text" name="school"  >' +
        '</div>' +
        '</div>' +
        '<div class="li">' +
        '<div class="title">' +
        '<span>' + i18next.t('info.studentnumber') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control a1" type="text" name="schoolNo" >' +
        '</div>' +
        '</div>' +
        '<div class="li">' +
        '<div class="title">' +
        '<span>' + i18next.t('info.grades') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control a1" type="text" name="grade" >' +
        '</div>' +
        '</div>' +

        '<div class="li">' +
        '<div class="title">' +
        '<span>' + i18next.t('info.subjects') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control a1" type="text" name="subject" >' +
        '</div>' +
        '</div>' +
        '<div class="li" style="height:180px;">' +
        '<div class="title" style="position:relative;left:0;top:5px;">' +
        '<span style="position:relative;left:0;top:70px;">' + i18next.t('info.studentphoto') + '：</span>' +
        '</div>' +
        '<div class="content" id="J_imgupload">' +
        '<span class="icon icon-uploadimg" id="J_uploadCover">' +
        '<img src="../images/img_transparent.png" width="180" height="180" id="J_img">' +
        '<input type="file" name="Filedata" multiple="multiple" data-url="/api/file/upload" class="a1" style="background:red">' +
        '</span>' +
        '</div>' +
        '</div>' +
        '<div class="li">' +
        '<div class="title">' +
        '<span>' + i18next.t('table.birth') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input type="text" class="form-control a1" size="16" data-type="date-input" name="dateofbirth" data-valuetype="single" data-value="0" value="选择时间" readonly="readonly" placeholder="请输入您出生年日期">' +
        '</div>' +
        '</div>' +

        '<div class="li">' +
        '<div class="title">' +
        '<span>' + i18next.t('table.city') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control a1" type="text" name="city" >' +
        '</div>' +
        '</div>' +
        '<div class="li">' +
        '<div class="title">' +
        '<span>' + i18next.t('info.parentname') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control a1" type="text" name="parentname" >' +
        '</div>' +
        '</div>' +
        '<div class="li">' +
        '<div class="title">' +
        '<span>' + i18next.t('info.parentphone') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        '<input class="form-control a1" type="text" name="parentmobile" >' +
        '</div>' +
        '</div>' +


        '<div class="li">' +
        '<div class="title">' +
        '<span>' + i18next.t('info.remarkps') + '：</span>' +
        '</div>' +
        '<div class="content">' +
        //'<input class="form-control a1" type="text" name="remark" placeholder="请输入您备注消息" style="width:508px;height:74px;word-break:break-all">' +
        '<textarea  rows="5" cols="69" style="border: 1px solid #ccc;border-radius: 5px;color:#818e9b;padding-left:15px;" name="remark" value=""></textarea>' +
        '</div>' +
        '</div>' +

        '</div>');
    $Addstudent.find('input[type="text"]').css('width', "182px");
    function getStudentmanagement(query, cb) {
        ajaxMethod({
            url: '/api/students',
            data: query || {},
            success: function (data) {
                //console.log(data);
                getstudentsData(data)
                cb && cb(data)
            }
        })
        function getstudentsData(data) {
            var $enrollmentTable = $('#J_enrollment').html('')
            var $thead = $('<thead>\
            <tr>\
                 <th>' + i18next.t('table.no') + '</th>\
                 <th>' + i18next.t('info.studentname') + '</th>\
                 <th>' + i18next.t('info.classinaccountnumber') + '</th>\
                 <th>' + i18next.t('info.studentphone') + '</th>\
                 <th>' + i18next.t('table.grade') + '</th>\
                 <th>' + i18next.t('info.subject') + '</th>\
                 <th>' + i18next.t('info.birth') + '</th>\
                 <th>' + i18next.t('info.city') + '</th>\
                 <th>' + i18next.t('info.parentname') + '</th>\
                 <th>' + i18next.t('info.parentphone') + '</th>\
                 <th>' + i18next.t('table.handle') + '</th>\
           </tr>\
          </thead>').appendTo($enrollmentTable)

            var $tbody = $('<tbody></tbody>').appendTo($enrollmentTable)
            $.each(data.list, function (index, item) {
                //console.log(item.name)
                var studentuid = item.studentuid;
                //var birthday = new Date(item.birthday).Format('YYYY-MM-DD')
                var $enroll = $('<tr class="enroll" data-uid="' + studentuid + '"></tr>')
                $enroll.append('<td></td>')
                $enroll.append('<td>' + item.name + '</td>')
                $enroll.append('<td>' + item.ClassInNo + '</td>')
                $enroll.append('<td>' + item.mobile + '</td>')
                $enroll.append('<td>' + item.grade + '</td>')
                $enroll.append('<td>' + item.subject + '</td>')
                $enroll.append('<td>' + (item.birthday == null ? "--" : item.birthday.substr(0, 10)) + '</td>')
                $enroll.append('<td>' + item.city + '</td>')
                $enroll.append('<td>' + item.parentname + '</td>')
                $enroll.append('<td>' + item.parentmobile + '</td>')
                var $handleTd = $('<td></td>').appendTo($enroll)
                var $editbtn = $('<a  class="ml5"><span class="	btn btn-primary btn-sm btn-inverse">' + i18next.t('course.compile') + '</span></a>').appendTo($handleTd);
                var $deletebtn = $('<a href="javascript:void(0);" class="ml5"><span class="btn btn-danger btn-sm btn-inverse">' + i18next.t('table.delete') + '</span></a>').appendTo($handleTd);
                //点击编辑按钮
                $editbtn.on('click', function () {
                    if ($Addstudent.find("input:not(#resetpassword)").val() != "") {
                        $Addstudent.find("input:not(#resetpassword)").val("");
                    }
                    $Addstudent.find("input[name=account]").parents(".li").show();
                    $Addstudent.find("input[name=ClassInNo]").attr("readonly", "readonly");
                    loadEnrollData(studentuid);
                    //$Addstudent.find("input[name=name]").attr("readonly", "readonly");
                    $Addstudent.find('#classIntest').hide();
                    ClearError($Addstudent);
                    var popUpBox = new PopUpBox({
                        type: 'dom',
                        style: 'default contentScroll',
                        submitBtnType: 'confirm',
                        keySubmit: false,
                        titleText: i18next.t('popupbox.pleaseinfo'),
                        show: true,
                        content: $Addstudent,
                        callback: {
                            yes: function (e) {
                                var Error = $('.inputErrorTips').text()
                                if (Error != '') {
                                    return false;
                                }
                                if ($Addstudent.find("input[type='text']").val() != "" && $Addstudent.find("input[name='mobile']").val() != "") {
                                    bindSubmit();
                                    //pagination.updateData()
                                } else {
                                    return false
                                }
                            }
                        },
                        position: {
                            width: 696,
                            height: 552
                        }
                    })
                    $(".popUpBoxFg").find('.close').on("click", function () {
                    })
                    $(".submitBtnBox").find('.btn-default').on("click", function () {
                    })
                })
                //删除
                $deletebtn.on('click', function () {
                    var popUpBox = new PopUpBox({
                        type: 'dom',
                        style: 'default contentScroll',
                        submitBtnType: 'confirm',
                        titleText: i18next.t('popupbox.systemmessages'),
                        show: true,
                        content: '<div style="margin-left:27px;margin-top:34px;">' + i18next.t('popupbox.del') + '?' + '</div>',
                        callback: {
                            yes: function (e) {
                                $.ajax({
                                    url: '/api/student/' + studentuid,
                                    type: "delete",
                                    success: function (data) {
                                        var popUpBox = new PopUpBox({
                                            type: 'dom',
                                            style: 'default contentScroll',
                                            submitBtnType: 'confirm',
                                            titleText: i18next.t('popupbox.systemmessages'),
                                            show: true,
                                            content: "<div style='margin-left:27px;margin-top:34px;'>" + data.status.message + "!</div>",
                                            callback: {
                                                yes: function (e) {
                                                    pagination.updateData()
                                                }
                                            },
                                            position: {
                                                width: 448,
                                                height: 226
                                            }
                                        })
                                    }
                                });
                            }
                        },
                        position: {
                            width: 448,
                            height: 226
                        }
                    })
                })
                $tbody.append($enroll);
                //排序
                var len = $('table tr').length;
                for (var i = 1; i < len; i++) {
                    $('table tr:eq(' + i + ') td:first').text(i);
                }
                //把所有null的字段都换成---
                $tbody.find("tr").each(function () {
                    //console.log(this)
                    var tdhtml = $(this).children();
                    $.each(tdhtml, function (i, t) {
                        //console.log($(t).text());
                        //console.log(t)
                        $(t).text() == 'null' ? $(t).text('--') : $(t).text()
                        $(t).text() == '0000-00-00' ? $(t).text('--') : $(t).text()
                        $(t).text() == '' ? $(t).text('--') : $(t).text()
                    })
                });

            })
        }
    }

    //导入功能
    function fileUpload($container) {
        var $uploadInput = $container.find('input')
        var coverUploadInput = new UploadInput({
            formData: {
                importer: 'student'
            },
            $dom: $uploadInput,
            done: function (uploadSrc) {
                if (uploadSrc != "true") {
                    var $import = $('<div style="padding-left:18px;margin-top:15px;"></div>').html('');
                    $.each(uploadSrc, function (index, exce) {
                        $("<p style='height:30px;line-height:30px;'><label style='display:inline-block;width:85px;'>" + exce.student.name + ":</label><label>" + exce.error + "</label></p>").appendTo($import);
                    })
                } else {
                    var $import = $('<div style="padding-left:18px;margin-top:15px;">' + i18next.t('popupbox.data') + '</div>');
                }
                var popUpBox = new PopUpBox({
                    type: 'dom',
                    style: 'default contentScroll',
                    submitBtnType: 'confirm',
                    keySubmit: false,
                    titleText: i18next.t('popupbox.importdata'),
                    show: true,
                    content: $import,
                    callback: {
                        yes: function (e) {
                            var uploadSrcN = '/api/file?u=' + uploadSrc;
                            window.location.reload();
                        }
                    },
                    position: {
                        width: 450,
                        height: 263
                    }
                })
            }
        });
    }

    fileUpload($('#J_container'))

    function loadSearchData(querystr) {
        if (querystr) {
            pagination.filter.ClassInNo = querystr
            pagination.filter.name = querystr
            pagination.filter.mobile = querystr

            pagination.searchData()
        } else {
            pagination.reloadData()
        }
    }

    //搜索
    $('#J_teacher_search').on('click', function () {
        var querystr = $("#searchInput").val();
        loadSearchData(querystr)
    })

    //检测
    var registerDefaultPwd = "";
    ajaxMethod({
        url: '/api/organization/1',
        type: 'get',
        success: function (data) {
            registerDefaultPwd = data.registerDefaultPwd;
        }
    })
    function classIn() {
        var classin_nov = "";
        $Addstudent.find('[name="ClassInNo"]').on("blur", function () {
            if ($Addstudent.find('[name="ClassInNo"]').val() == "") {
                $('input[name="ClassInNo"]').next(".inputErrorTips").css({
                    "display": "block",
                    "margin-left": "117px"
                }).text("该项不能为空")
            }
            classIntest(true);
        })
        function classIntest(cl) {
            classin_nov = $Addstudent.find('[name="ClassInNo"]').val();
            ajaxMethod({
                url: '/api/eeo/check',
                method: 'post',
                data: {account: classin_nov},
                success: function (data, status) {
                    if (status.code == 0) {
                        $('input[name="ClassInNo"]').next(".inputErrorTips").hide();
                        if (data == "true") {
                            $Addstudent.find('.pw').hide();
                            $Addstudent.find('#prompt').show();
                            $Addstudent.find('#noprompt').hide();
                            $Addstudent.find("#resetpassword").attr("disabled", false)
                            needPw = false;
                        }
                        else {
                            $Addstudent.find('.pw').show();
                            $Addstudent.find('#noprompt').show();
                            $Addstudent.find('[name="pw"]').val(registerDefaultPwd);
                            $Addstudent.find('#prompt').hide();
                            needPw = true;
                            $("#resetpassword").attr("disabled", true);
                        }
                    } else {
                        $Addstudent.find('.pw').hide();
                        $Addstudent.find('#prompt').hide();
                        $("#resetpassword").attr("disabled", false);
                        needPw = false;
                        if ($('input[name="ClassInNo"]').val() != "") {
                            $('input[name="ClassInNo"]').next(".inputErrorTips").css({
                                "display": "block",
                                "margin-left": "117px"
                            }).text(status.message);
                        }
                    }
                }
            })
        }
    }

    $Addstudent.find('[name="pw"]').on('blur', function () {
        if ($Addstudent.find('[name="pw"]').val() != "") {
            $Addstudent.find('#prompt').hide();
            $Addstudent.find('#noprompt').hide();
        } else {
            $Addstudent.find('#noprompt').show();
        }
    })
    //重置密码
    var account = "";
    $Addstudent.find("#resetpassword").on('click', function () {
        account = $Addstudent.find('[name="ClassInNo"]').val();
        var $ClassInDom = $('<div class="formList" id="J_teacheradd_wrap" style="margin-top:12px;">\
          <div class="formLi" >\
            <div class="formLi" >\
              <div class="formTitle required">\
                  <span>新&nbsp&nbsp&nbsp密&nbsp&nbsp&nbsp码</span>\
              </div>\
              <div class="formContent">\
                  <input class="form-control" data-formcheck="length" type="text"  name="passwordnew" style="width:226px;">\
              </div>\
          </div>\
          <div class="formLi" >\
              <div class="formTitle required">\
                  <span>确认新密码</span>\
              </div>\
              <div class="formContent">\
                  <input class="form-control" data-formcheck="length" type="text"  name="passwordold" style="width:226px;">\
                  <p style="color:red;display:none;margin-top:30px;" class="p">两次输入密码不一致</p>\
              </div>\
            </div>\
          </div>');
        var popUpBox = new PopUpBox({
            ype: 'dom',
            style: 'default autoResize',
            submitBtnType: 'alert',
            closeClear: false,
            titleText: '请输入设置的密码',
            show: true,
            content: $ClassInDom,
            callback: {
                yes: function (e) {
                    var passwordold = $ClassInDom.find('[name="passwordold"]').val();
                    var passwordnew = $ClassInDom.find('[name="passwordnew"]').val();
                    //console.log(account);
                    if (passwordold != "" || passwordnew != "") {
                        if (passwordold != passwordnew) {
                            $('.p').show();
                            return false;
                        } else {
                            $('.p').hide();
                            ajaxMethod({
                                url: '/api/eeo/reset',
                                method: 'post',
                                data: {
                                    account: account,
                                    password: passwordold
                                },
                                success: function (data, status) {
                                    if (status.code != 0) {
                                        _Tips(status.message)
                                    }

                                }
                            })
                        }
                    } else {
                        return false;
                    }
                }
            },
            position: {
                width: 423,
                height: 304,
            }
        })
        popUpBox.submitBtnBox.$dom.css('text-align', 'right')
        $(".popUpBoxFg").find('.close').show();
    })
    //添加学生
    $("#addStudent").on("click", function () {
        $Addstudent.find("input[name=ClassInNo]").removeAttr("readonly");
        $Addstudent.find("input[name=account]").parents(".li").hide();
        $Addstudent.find('#resetpassword').hide();
        $Addstudent.find('#classIntest').hide();
        classIn()
        $Addstudent.find("input[name=name]").removeAttr("readonly");
        $Addstudent.find('input[type="text"]').val("");
        $Addstudent.find("#J_img").attr("src", "");
        ClearError($Addstudent);
        var popUpBox = new PopUpBox({
            type: 'dom',
            style: 'default contentScroll',
            submitBtnType: 'confirm',
            titleText: i18next.t('popupbox.pleaseinfo'),
            keySubmit: false,
            show: true,
            content: $Addstudent,
            callback: {
                yes: function (e) {
                    if (FormCheck.childrenInputCheck($Addstudent)) {
                        var ClassInNo = $Addstudent.find('[name=ClassInNo]').val();
                        var name = $Addstudent.find('[name=name]').val();
                        var mobile = $Addstudent.find('[name=mobile]').val();
                        var Error = $('.inputErrorTips').text()
                        if (ClassInNo != "" && name != "" && mobile != "") {
                            entersubmit();
                        }
                    } else {
                        return false;
                    }

                    function entersubmit() {
                        var sex = $('[name="gender"]:checked').val();
                        var studentuid = $Addstudent.find('[name=studentuid]').val()
                        var ClassInNo = $Addstudent.find('[name=ClassInNo]').val()
                        var account = $Addstudent.find('[name=ClassInNo]').val()
                        var name = $Addstudent.find('[name=name]').val()
                        var fullname = $Addstudent.find('[name=fullname]').val()
                        var mobile = $Addstudent.find('[name=mobile]').val()
                        var email = $Addstudent.find('[name=email]').val()
                        var grade = $Addstudent.find('[name=grade]').val()
                        var subject = $Addstudent.find('[name=subject]').val()
                        var dateofbirth = $Addstudent.find('[name=dateofbirth]').val()
                        var city = $Addstudent.find('[name=city]').val()
                        var parentname = $Addstudent.find('[name=parentname]').val()
                        var parentmobile = $Addstudent.find('[name=parentmobile]').val()
                        var remark = $Addstudent.find('[name=remark]').val()
                        var school = $Addstudent.find('[name=school]').val()
                        var schoolNo = $Addstudent.find('[name=schoolNo]').val()
                        var password = $Addstudent.find('[name=pw]').val()
                        var photo = $Addstudent.find('#J_uploadCover img').attr('src');
                        var Studentroll = {
                            ClassInNo: ClassInNo,
                            account: account,
                            name: name,
                            mobile: mobile,
                            photo: photo,
                            grade: grade,
                            subject: subject,
                            birthday: dateofbirth,
                            city: city,
                            email: email,
                            parentname: parentname,
                            parentmobile: parentmobile,
                            remark: remark,
                            schoolNo: schoolNo,
                            school: school,
                            sex: sex
                        }
                        if (needPw = false) {
                            ajaxMethod({
                                url: '/api/student',
                                type: 'post',
                                data: Studentroll,
                                success: function (data, status) {
                                    //alert('保存成功');
                                    if (status.code != 0) {
                                        _Tips(status.message)
                                    } else {
                                        window.location.reload();
                                    }

                                }
                            });
                        } else {
                            ajaxMethod({
                                url: '/api/student',
                                type: 'post',
                                data: $.extend({}, Studentroll, {password: password}),
                                success: function (data, status) {
                                    if (status.code != 0) {
                                        _Tips(status.message)
                                    } else {
                                        window.location.reload();
                                    }
                                }
                            });
                        }
                    }
                }
            },
            position: {
                width: 696,
                height: 552
            }
        })
        $(".popUpBoxFg").find('.close').on("click", function () {
            $Addstudent.find('.pw').hide();
        })

    })

    //编辑传值
    var $studentuid = $Addstudent.find('[name=studentuid]')
    var $ClassInNo = $Addstudent.find('[name=ClassInNo]')
    var $name = $Addstudent.find('[name=name]')
    var $fullnam = $Addstudent.find('[name=fullname]')
    var $mobile = $Addstudent.find('[name=mobile]')
    var $email = $Addstudent.find('[name=email]')
    var $photo = $Addstudent.find("#J_img")
    var $grade = $Addstudent.find('[name=grade]')
    var $subject = $Addstudent.find('[name=subject]')
    var $city = $Addstudent.find('[name=city]')
    var $parentname = $Addstudent.find('[name=parentname]')
    var $parentmobile = $Addstudent.find('[name=parentmobile]')
    var $dateofbirth = $Addstudent.find('[name=dateofbirth]')
    var $remark = $Addstudent.find('[name=remark]')
    var $school = $Addstudent.find('[name=school]')
    var $schoolNo = $Addstudent.find('[name=schoolNo]')
    var studentuid = location.search.urlToObj().studentuid
    //图片上传$Addstudent
    function imgUpload($container) {
        var $uploadCoverBox = $container.find('.icon-uploadimg')
        var $uploadCoverThumb = $uploadCoverBox.find('img')
        var $uploadInput = $uploadCoverBox.find('input')
        var coverUploadInput = new UploadInput({
            $dom: $uploadInput,
            done: function (uploadSrc) {
                console.log(uploadSrc);
                var uploadFullSrc = '/api/file?u=' + uploadSrc;
                if (uploadSrc) {
                    new ImgCropTool({
                        imgSrc: uploadFullSrc,
                        cropSize: [200, 200, 'courseCover'],
                        success: function (imgSrc) {
                            var imgCropSrc = '/api/file?u=' + imgSrc;
                            $uploadCoverBox.attr('data-value', imgCropSrc);
                            $uploadCoverThumb.attr('src', imgCropSrc);
                        }
                    })
                }
            }
        });
    }

    function getFileNameByPath(src) {
        return src.replace(/^.+\/([^\/]+)$/, function () {
            if (arguments[1]) {
                return arguments[1]
            }
            return ''
        });
    }

    function loadEnrollData(studentuid, callback) {
        ajaxMethod({
            url: '/api/student/' + studentuid,
            dataType: 'json',
            success: function (data) {
                $Addstudent.find('input[value="' + data.sex + '"]').click();
                $Addstudent.find('[name=studentuid]').val(data.studentuid);
                $Addstudent.find('[name=ClassInNo]').val(data.ClassInNo);
                $Addstudent.find('[name=account]').val(data.account);
                $Addstudent.find('[name=name]').val(data.name);
                $Addstudent.find('[name=fullname]').val(data.fullname);
                $Addstudent.find('[name=mobile]').val(data.mobile);
                $Addstudent.find('[name=email]').val(data.email);
                $Addstudent.find('[name=grade]').val(data.grade);
                $Addstudent.find('[name=subject]').val(data.subject);
                $Addstudent.find('[name=city]').val(data.city);
                $Addstudent.find('[name=parentname]').val(data.parentname);
                $Addstudent.find('[name=parentmobile]').val(data.parentmobile);
                $Addstudent.find('[name=remark]').val(data.remark);
                $Addstudent.find('[name=school]').val(data.school);
                $Addstudent.find('[name=schoolNo]').val(data.schoolNo);
                $photo.attr('src', data.photo);
                $Addstudent.find('[name=dateofbirth]').val(data.birthday != "0000-00-00 00:00:00" ? data.birthday.substr(0, 10) : "请选择日期");
                (typeof callback == 'function') && callback();
            }
        })
    }

    function bindSubmit(data) {
        if (FormCheck.childrenInputCheck($Addstudent.find('#J_enroll_wrap'))) {
            var sex = $('[name="gender"]:checked').val();
            var studentuid = $Addstudent.find('[name=studentuid]').val()
            var ClassInNo = $Addstudent.find('[name=ClassInNo]').val()
            var name = $Addstudent.find('[name=name]').val()
            var fullname = $Addstudent.find('[name=fullname]').val()
            var mobile = $Addstudent.find('[name=mobile]').val()
            var email = $Addstudent.find('[name=email]').val()
            var grade = $Addstudent.find('[name=grade]').val()
            var subject = $Addstudent.find('[name=subject]').val()
            var dateofbirth = $Addstudent.find('[name=dateofbirth]').val()
            var city = $Addstudent.find('[name=city]').val()
            var parentname = $Addstudent.find('[name=parentname]').val()
            var parentmobile = $Addstudent.find('[name=parentmobile]').val()
            var remark = $Addstudent.find('[name=remark]').val()
            var school = $Addstudent.find('[name=school]').val()
            var schoolNo = $Addstudent.find('[name=schoolNo]').val()
            var photo = $Addstudent.find('#J_uploadCover img').attr('src');
            var Studentroll = {
                ClassInNo: ClassInNo,
                name: name,
                mobile: mobile,
                photo: photo,
                grade: grade,
                subject: subject,
                birthday: dateofbirth,
                city: city,
                email: email,
                parentname: parentname,
                parentmobile: parentmobile,
                remark: remark,
                school: school,
                schoolNo: schoolNo,
                sex: sex
            }
            if (studentuid != undefined) {
                ajaxMethod({
                    url: '/api/student/' + studentuid,
                    type: 'put',
                    data: $.extend(Studentroll, {studentuid: studentuid}),
                    success: function (data, status) {
                        if (status.code != 0) {
                            _Tips(status.message)
                        } else {
                            window.location.reload();
                        }
                    }
                });
            }
        }
    }

    imgUpload($Addstudent.find('#J_imgupload'))

    pagination = new Pagination($pagination, getStudentmanagement)

})
